package cn.bgs.service.impl;

import cn.bgs.common.Results;
import cn.bgs.dao.StudentMapper;
import cn.bgs.entity.Areas;
import cn.bgs.entity.Cities;
import cn.bgs.entity.Provinces;
import cn.bgs.entity.Student;
import cn.bgs.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired private StudentMapper studentMapper;
    @Autowired private StudentMapper provincesMapper;
    @Autowired private StudentMapper citiesMapper;
    @Autowired private StudentMapper areasMapper;


    @Override
    public Results stuOneId(Integer stuId) {
        Results result = new Results();
        Student student = studentMapper.stuOneId(stuId);

        List<Provinces> provinces =  provincesMapper.select();
        List<Cities> cities = citiesMapper.getCities(Integer.valueOf(student.getProvincesId()));
        List<Areas> areas = areasMapper.getAreas(Integer.valueOf(student.getCitiesId()));
        Map<Object, Object> map = new HashMap<>();
        if(student != null){
            result.setMsg("查询成功");
            //学生信息
            map.put("students",student);
            //省
            map.put("provinces",provinces);
            //市
            map.put("cities",cities);
            //县
            map.put("areas",areas);
            result.setData(map);
            return result;
        }else{

            result.setMsg("查询失败");
            result.setData(student);
            return result;
        }
    }

    @Override
    public List<Cities> getCities(Integer provinceId) {
        return citiesMapper.getCities(provinceId);
    }

    @Override
    public List<Areas> getAreas(Integer cityId) {
        return areasMapper.getAreas(cityId);
    }

    @Override
    public Results getProvinces() {
        Results result = new Results();
        List<Provinces> provinces =  provincesMapper.select();
        if(provinces.size() != 0){
            result.setMsg("查询成功");
            result.setData(provinces);
            return result;
        }else{
            result.setMsg("查询失败");
            return result;
        }
    }

}
